package com.example.practice;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.example.practice.bean.SensorValue;
import com.example.practice.service.DataService;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;

public abstract class BaseActivity extends FragmentActivity{
	
	private static List<Activity> activities = new ArrayList<Activity>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		handler.postDelayed(runnable, 1000);
		activities.add(this);
		startService(new Intent(this,DataService.class));
	}
	
	protected abstract void onGetSensorValue(SensorValue sensorValue);
	
	private Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			
		};
	};
	
	
	private Runnable runnable =new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			onGetSensorValue(DataService.sensorValue);
			handler.postDelayed(runnable,1000);
		}
	};
	
	protected void onDestroy() {
		super.onDestroy();
		handler.removeCallbacks(runnable);
	};
}
